package com.broada.apm.logic;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.ws.rs.PathParam;

import com.broada.apm.entity.Alarm;
import com.broada.apm.entity.AlertSeverity;
import com.broada.apm.model.Alert;
import com.broada.apm.model.PagingList;
import com.broada.apm.model.Threshold;

public interface AlertLogic {
	/**
	 * 根据条件查询告警
	 * 
	 * @param alert
	 * @param pageIndex
	 * @param pageSize
	 * @return
	 */
	public PagingList<Alarm> queryAlert(int severity, String alertType, Date startTime, Date endTime, String source,
			int status, int clearStatus,String keyWord, String sortField, String sortBy, int pageIndex, int pageSize);

	/**
	 * 根据告警ID删除告警
	 * @param ids
	 */
	public void deleteAlertById(String... ids);
	
	/**
	 * 删除应用系统中的告警
	 * @param alert
	 */
	public void deleteAlert(Alert alert);

	/**
	 * 确认告警
	 * 
	 * @param ids
	 * @return
	 */
	public void updateAlertStatus(int status,String... ids);

	/**
	 * 统计查询，返回所有告警等级对应的告警数 注：未处理
	 * 
	 * @return
	 */
	public List<Map<String, Object>> queryAlertStaticBySeverity();

	/**
	 * 统计查询，根据告警等级返回对应的告警数 注：未处理
	 * 
	 * @return
	 */
	public int queryAlertCountByWorstSeverity();

	/**
	 * 返回所有告警等级
	 * 
	 * @return
	 */
	public List<AlertSeverity> queryAlertSeverity();

	/**
	 * 查询最新告警,未处理/新告警
	 * 
	 * @param appId
	 * @param id
	 * @param type
	 *          判断id类型
	 * @param rows
	 *          条数
	 * @return
	 */
	public List<Alarm> queryAlertByType(String appId, String id, String type, int rows, String keyWord, String panelId, Date startDate, Date endDate, int severity);

	/**
	 * 告警阀值配置
	 * 
	 * @param appId
	 *          应用系统id
	 * @param threshold
	 *          阀值配置对象
	 */
	public boolean saveThreshold(@PathParam("appId") String appId, Threshold threshold, String panelId);
	

	/**
	 * 告警阀值配置查询编辑
	 * 
	 * @param appId
	 * @param targetId
	 * @return
	 */
	public com.broada.apm.entity.Threshold queryThresholdByTargetId(String appId, String targetId, String thresholdType, String panelId);

	/**
	 * 告警阀值配置列表查询
	 * 
	 * @param appId
	 * @return
	 */
	public List<com.broada.apm.entity.Threshold> queryThresholdsByApplicationId(String appId, String panelId);

	/**
	 * 告警阀值配置删除
	 * 
	 * @param appId
	 * @param targetId
	 * @return
	 */
	public boolean deleteThresholdsByTargetId(String appId, String targetId, String thresholdType, String panelId);

	/**
	 * 查询不同等级对应的产生告警的主机数
	 * @return
	 */
	public List<Map<String, Object>> queryServerCountBySeverity() throws Exception;

	public Integer queryAppAlertCount(String appId, Date startTime, Date endTime);

	public Map<String, Map<String, Object>> queryAlertByServiceAndSeverity(List<String> servIdList, Date startTime, Date endTime, int severity);

	/**
	 * 查询某个应用系统或节点的各个不同级别的告警数
	 * @param groupBy
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public Map<String, Map<String, String>> queryAlertCountBySeverity(String groupBy, Date startTime, Date endTime);

	/**
	 * 查询某个应用系统或节点的各个不同类型的告警数
	 * @param type
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public Map<String, Map<String, String>> queryAlertCountByType(String type, Date startTime, Date endTime);

}
